<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<title>微信扫一扫</title>
<link rel="stylesheet" href="https://res.wx.qq.com/open/libs/weui/1.1.3/weui.min.css">
</head>
<body>
	<div class="page">
		<div class="weui-msg">
			<div class="weui-msg__icon-area">
				<i class="weui-icon-success weui-icon_msg"></i>
			</div>
			<div class="weui-msg__text-area">
				<h2 class="weui-msg__title">二维码内容</h2>
				<p class="weui-msg__desc"></p>
			</div>
			<div class="weui-msg__opr-area">
				<p class="weui-btn-area">
					<a href="javascript:history.back();" class="weui-btn weui-btn_primary">推荐操作</a>
				</p>
			</div>
			<div class="weui-msg__extra-area">
				<div class="weui-footer">
					<p class="weui-footer__links">
						<a href="javascript:void(0);" class="weui-footer__link">底部链接文本</a>
					</p>
					<p class="weui-footer__text">Copyright &copy; 2008-2016 weui.io</p>
				</div>
			</div>
		</div>
		
		<div id="toast" style="display: none;">
			<div class="weui-mask_transparent"></div>
			<div class="weui-toast">
				<i class="weui-icon-success-no-circle weui-icon_toast"></i>
				<p class="weui-toast__content"></p>
			</div>
		</div>
	</div>
</body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="http://res.wx.qq.com/open/js/jweixin-1.4.0.js"></script>
<script src="https://res.wx.qq.com/open/libs/weuijs/1.1.4/weui.min.js"></script>
<script src="js/url.js"></script>
<script type="text/javascript">
$(function(){
	var appId = getUrlParam('state');
	showToast(appId);
	$.ajax({
		async: false,
		url: DOMAIN_NAME + '/weixin/jsSdkConfig',
		type: 'POST',
		contentType: 'application/json;charset=utf-8',
		dataType: 'json',
		data: JSON.stringify({
			'appId': appId,
			'url': DOMAIN_NAME + '/scan_qrcode.html'
		}),
		success(result,status,xhr){
			if(status == 'success') {
				wx.config( {
					debug : true, 
					appId : appId, 
					timestamp : result.timestamp, 
					nonceStr : result.nonceStr, 
					signature : result.signature,
					jsApiList : [ 
						'scanQRCode'
					]
				});
				
				wx.ready(function() { 
					$('#scanBtn').click(function() {
						wx.scanQRCode({
							needResult: 1, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，
							scanType: ['qrCode'], // 可以指定扫二维码还是一维码，默认二者都有
							success: function (res) {alert(3);
								var result = res.resultStr; // 当needResult 为 1 时，扫码返回的结果
								$('.weui-msg__desc').html(result);
							}
						});
					});
				});			
				
				wx.error(function(res) {
					console.log('wx.error', res);
				});
			}
		}, 
		error(xhr,status,error){
			console.log('status', status);
			console.log('error', error);
		}
	});
});

var $toast = $('#toast');
function showToast(content){
    if ($toast.css('display') != 'none') return;
	
    $toast.find('p.weui-toast__content').html(content);
    
    $toast.fadeIn(100);
    setTimeout(function () {
        $toast.fadeOut(100);
    }, 2000);
}
</script>
</html>